<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use common\helpers\StringHelper;
use yii\bootstrap\Modal;
use johnitvn\ajaxcrud\CrudAsset;
use yii\widgets\Pjax;

$this->title = 'Team';
CrudAsset::register($this);
?>
<div class="blog-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p class="text-right">
        <?= Html::a('ADD', ['create-team'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'responsiveWrap' => false,
        'dataProvider' => $dataProvider,
        'columns' => [
            'id',
            'name',
            [
                'attribute' => 'description',
                'value' => function ($model) {
                    return StringHelper::truncateMsg($model->description, 50);  //显示省略号
                }
            ],
            [
                'attribute' => 'ctime',
                'label' => 'Ctime',
                'format'=>'raw',
                'value' => function ($model){
                    return date("Y-m-d H:i:s",$model->ctime);
                }
            ],
            [
                'class' => 'kartik\grid\ActionColumn',
                'template' => '{view-team}{update-team}{add-team-user}',
                'buttons' => [
                    'view-team' => function ($url, $model) {
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>View', $url, [
                            'title' => Yii::t('yii', 'View'),
                            'class' => 'btn btn-default btn-sm'
                        ]);
                    },
                    'update-team' => function ($url, $model) {
                        return Html::a('<span class=" glyphicon glyphicon-pencil"></span>Update', $url, [
                            'title' => Yii::t('yii', 'Update'),
                            'class' => 'btn btn-default btn-sm'
                        ]);
                    },
                    'add-team-user' => function ($url, $model) {
                        return Html::a('<span class="glyphicon glyphicon-plus"></span>Add User', $url, [
                            'title' => Yii::t('yii', 'Add User'),
                            'class' => 'btn btn-default btn-sm',
                            'role' => 'modal-remote',
                        ]);
                    },
                ]
            ],
        ],
    ]); ?>

</div>

<?php Modal::begin([
    "id" => "ajaxCrudModal",
    "options" => ["tabindex" => ""],
    "footer" => "",
]) ?>
<?php Modal::end(); ?>

<script type="text/javascript">
    $(function () {
        if($('.alert').length > 0){
            setTimeout(function() {
                $('.alert').slideUp(500);
            }, 3000);
        }
    });
</script>
